package ooday04;

public class AnimalTest {
    static int a = 2;

    public static void main(String[] args) {
        //演示向上造型（多态）的第2点应用
        /*
        Master master = new Master();
        Dog dog = new Dog("小黑",2,"黑");
        Chick chick = new Chick("小白",2,"白");
        Fish fish = new Fish("小花",2,"花");
        master.feed(dog); //在传参的同时，系统自动做了向上造型
        master.feed(chick);
        master.feed(fish);
         */


        //演示向上造型（多态）的第1点应用
        /*
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 2, "白");
        animals[2] = new Chick("小金", 2, "金");
        animals[3] = new Chick("小花", 2, "花");
        animals[4] = new Fish("小灰", 2, "灰");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog) {
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick) {
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim) { //若能游泳(实现Swim接口的)
                Swim swim = (Swim) animals[i];
                swim.swim();
            }
        }
         */

        Aoo aoo = new Aoo() {
            @Override
            void show() {
                a = 10;
                System.out.println(a);
            }
        };
        aoo.show();

    }
}


abstract class Aoo {
    abstract void show();
}

class Boo{

}
